/*
 *  output_1d.cc
 *  uqtool
 *
 *  Created by Praveen Chandrashekar on 19/12/10.
 *  Copyright 2010 TIFR-CAM, Bangalore. All rights reserved.
 *
 */

#include <fstream>
#include <cassert>
#include "uq.h"

using namespace std;

// Save stochastic grid and functionals into file for
// visualization. 
template <>
void UQProblem<2>::output (const unsigned int iter) const
{
   assert (n_moment == 1);
   
   char filename[64];
   
   sprintf(filename, "RESULT/grid_%d.plt", iter);
   ofstream fo;
   fo.open (filename);
   fo.precision (15);
   
   fo << "TITLE = \"Generated by uqtool\"\n";
   fo << "VARIABLES = \"X\", \"Y\", \"J\"\n";
   fo << "ZONE NODES=" << sample.size()
      << ", ELEMENTS=" << grid.n_active_elements()
      << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE\n";
   
   for(unsigned int i=0; i<sample.size(); ++i)
   {
      fo << sample[i].x[0] << " "
         << sample[i].x[1] << " "
         << sample[i].J[0] << endl;
   }
   
   for(unsigned int i=0; i<grid.element.size(); ++i)
      if(grid.element[i].active)
      {
         fo << 1+grid.element[i].idof[0] << " "
            << 1+grid.element[i].idof[1] << " "
            << 1+grid.element[i].idof[2] <<  endl;
      }
   
   fo.close ();
}
